package com.aaa.controller;

import com.aaa.annotation.MyAnnotation;
import com.aaa.entity.Staff;
import com.aaa.service.StaffService;
import com.aaa.vo.LoginVo;
import com.aaa.vo.R;
import com.aaa.vo.StaffVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
@Controller
@RequestMapping("/staff")
public class StaffController {
    @Autowired
    private StaffService staffService;
    //条件分页查询
    @RequestMapping("/list")
    @ResponseBody
    public R list(Integer currentPage, Integer pageSize, @RequestBody StaffVo staffVo){
        R r=staffService.findByCondition(currentPage,pageSize,staffVo);
        return r;
    }
    @RequestMapping("checkStaffId")
    @ResponseBody
    public R checkStaffId(String id){
        System.out.println(id+"~~~~~~~~~~~~~~~~~~~~~~");
        R r = staffService.checkStaffId(id);
        return r;
    }
    @RequestMapping("/login")
    @ResponseBody
    public R login(@RequestBody LoginVo loginVo){ //字符串。 ---> 可以封装一个新的类--接受传递
        System.out.println("******************************登录******************");
//        int c=10/0;
        R r = staffService.findByNameAndPwd(loginVo.getUsername(), loginVo.getPassword());
        return r;
    }
    @RequestMapping("/logout")
    @ResponseBody
    @MyAnnotation(name="退出登录")
    public R logout(HttpSession session){
        session.removeAttribute("staff");
        return new R(200,"退出成功",null);
    }

    @RequestMapping("/info")
    @ResponseBody
    @MyAnnotation(name="获取当前登录信息")
    public R info(HttpSession session){
        //获取当前登录的信息.
        Object staff = session.getAttribute("staff");
        return new R(200,"获取成功",staff);
    }

    @RequestMapping("/add")
    @ResponseBody
    @MyAnnotation(name="添加员工")
    public R add(@RequestBody Staff staff){
        R r = staffService.insert(staff);
        return r;
    }



}













